// pages/smallTeamInfo/smallTeamInfo.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    smteamId:'',
    session_key:'',
    subteam_list:{},//小分队信息
    subteam_leader: {},//小分队发起人
    subteam_users: [],//小分队人数
    teamid:'',
    httpPath: app.globalData.imagePath,
    peopleNum:''//球队总人数
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    var _key = wx.getStorageSync("token");
    that.setData({
      smteamId:options.subteamId
    })
    //小分队信息
    wx.request({
      url: app.globalData.httpsPath + '/subteam/show',
      method: 'POST',
      header: {
        'content-type': 'application/json'
      },
      data: {
        token: _key,
        subteam_id: options.subteamId
      },
      //请求后台数据成功  
      success: function (res) {
        var fendui_arr = res.data.data;
        var fendui_faqiren = res.data.data.leader;
        var fendui_duiyuan = res.data.data.users;

        that.setData({
          subteam_list: fendui_arr,
          subteam_leader: fendui_faqiren,
          subteam_users: fendui_duiyuan,
          teamid: fendui_arr.pid
        })

        //获取球队信息
        wx.request({
          url: app.globalData.httpsPath + '/team/users',
          method: 'POST',
          header: {
            'content-type': 'application/json'
          },
          data: {
            token: _key,
            team_id: that.data.subteam_list.pid
          },
          //请求后台数据成功  
          success: function (res) {
            var _teamNum = res.data.data.length;
            if (_teamNum != 0) {
              that.setData({
                peopleNum: _teamNum
              })
            }
          }
        })

      }
    })
    
  },
  //修改
  editBtn:function(){
    wx.navigateTo({
      url: '../smallTeamEdit/smallTeamEdit?fenduiID=' + this.data.smteamId
    })
  },
  
})